<?php
$root = $_SERVER['DOCUMENT_ROOT'];
include($root . "/util/session.php"); //checks that the user is logged in
include($root . "/util/privilege_check.php");
checkPrivilege("teacher");
?>
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta name="description" content="Teacher panel">
  <link href="https://fonts.googleapis.com/css2?family=Roboto:wght@400&display=swap" rel="stylesheet">
  <link rel="stylesheet" type="text/css" href="teacherStyle.css">
  <link rel="stylesheet" type="text/css" href="question.css">
  <title>Teacher main page</title>
</head>

<body>
  <?php
  include($root . "/teacher/header.php");

  if (isset($_SESSION['questionAdd'])) {
    if (!isset($_POST['questionTypeMultiple'])) {
      include($root . "/teacher/question_true_false_form.php");
    } else {
      include($root . "/teacher/question_multiple_form.php");
    }
  } else if (isset($_POST['chapterPanel']) || isset($_SESSION['chapterPanel'])) {
    setChapters();
    include($root . "/teacher/chapterPage.php");
  } else if (isset($_POST['subjectPanel']) || isset($_SESSION['subjectPanel'])) {
    setSubjects();
    include($root . "/teacher/subjectPage.php");
  } else {
    include($root . "/teacher/mainPage.php");
  }


  include($root . "/teacher/footer.php");


  function setChapters()
  {
    if (!isset($_SESSION['chapterPanel'])) {
      if (isset($_POST['chapterPanel'])) {
        $chapter = $_POST['chapterPanel'];
        $_SESSION['chapterPanel'] = $chapter;
      }
    }
  }

  function setSubjects()
  {
    if (!isset($_SESSION['subjectPanel'])) {
      if (isset($_POST['subjectPanel'])) {
        $chapter = $_POST['subjectPanel'];
        $_SESSION['subjectPanel'] = $chapter;
      }
    }
  }
  ?>
</body>